/*
 * Copyright (c) 2022 HiSilicon (Shanghai) Technologies CO., LIMITED.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
 
#ifndef UART_H
#define UART_H

#include <hi_type.h>

#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif
#endif /* __cplusplus */

#define RIGHT_MOVE_8_BIT (8)
#define HISGNALLING_MSG_FRAME_HEADER_LEN    (2)
#define HISIGNALLING_MSG_HEADER_TAIL_LEN    (4)
#define HISIGNALLING_MSG_ONE_FRAME_LEN      (12)

#define HISIGNALLING_HEAD_1 (0xAA)
#define HISIGNALLING_HEAD_2 (0x55)

#define HISGNALLING_FREE_TASK_TIME          (100)
#define HISIGNALLING_MSG_BUFF_LEN           (50)

/*
 * @brief 外设扩展板和Robot板的选择
 * 使用时选择打开宏，使用外设扩展板打开#define BOARD_SELECT_IS_EXPANSION_BOARD这个宏
 * 使用Robot板打开#define BOARD_SELECT_IS_ROBOT_BOARD这个宏
 *
 * @brief Selection of peripheral expansion board and Robot board
 * Select to open the macro when using it,
 * and use the peripheral expansion board to open the #define BOARD_SELECT_IS_EXPANSION_BOARD macro
 * Use the Robot board to open the #define BOARD_SELECT_IS_ROBOT_BOARD macro
 */

typedef enum {
    isTrackingStart = 0x01,
    TargetRoiPosi,
    GestureClass
} refuseClassification;

typedef struct {
    unsigned char frameHeader[HISGNALLING_MSG_FRAME_HEADER_LEN];
    refuseClassification frameType;
    unsigned char dataLen;
    unsigned char hisignallingMsgBuf[HISIGNALLING_MSG_BUFF_LEN];
    unsigned int hisigallingMsgLen;
} HisignallingProtocalType;

typedef enum {
    HISIGNALLING_RET_VAL_CORRECT = 0,
    HISIGNALLING_RET_VAL_ERROR,
    HISGNALLING_RET_VAL_MAX
} HisignallingErrorType;

/*
 * hisignalling协议函数声明
 * hisignalling protocal Function declaration
 */
unsigned short crc16(const unsigned char *buf, unsigned int size);

unsigned int UartOpenInit(void);

HisignallingErrorType HisignallingMsgReceive(int fd, unsigned char *buf, unsigned int len);

unsigned int HisignallingMsgSend(int fd, char *buf, unsigned int dataLen, refuseClassification frameType);

#ifdef __cplusplus
#if __cplusplus
}
#endif
#endif /* __cplusplus */

#endif